package com.vdcloud.mcclassroom.vo;

import com.vdcloud.mcclassroom.vo.respvo.LoginSuccessVO;
import lombok.Data;
import lombok.Setter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author songfazhun
 * @description:用于校验的用户对象
 */
@Data
public class UserDetail extends LoginSuccessVO implements UserDetails {

    /**
     * 是否记住密码
     */
    private Boolean remember;

    /**
     * 用户名
     */
    private String userAccount;

    /**
     * 用户密码
     */
    private String password;


    /**
     * 获取权限信息
     *
     * @return
     */
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        List<SimpleGrantedAuthority> list = getRoles().stream().map(roleName -> new SimpleGrantedAuthority("ROLE_" + roleName)).collect(Collectors.toList());
        return list;
    }


    /**
     * 获取密码
     *
     * @return
     */
    @Override
    public String getPassword() {
        return password;
    }

    /**
     * 获取账号
     *
     * @return
     */
    @Override
    public String getUsername() {
        return userAccount;
    }

    /**
     * 是否未过期
     *
     * @return
     */
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 是否未锁定
     *
     * @return
     */
    @Override
    public boolean isAccountNonLocked() {
        return false;
    }

    /**
     * 账户凭证是否未过期
     *
     * @return
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return false;
    }

    /**
     * 是否有效
     *
     * @return
     */
    @Override
    public boolean isEnabled() {
        return false;
    }
}
